package com.interview.javabase.algorithm.动态规划;

import java.util.Arrays;

/**
 * 10,9,2,5,3,7,101,18
 *
 * @author www.byteblogs.com
 * @date 2021-10-06
 * @since 2.0
 */
public class 动态递增子序列 {

    public static void main(String[] args) {

        int[] arr = new int[]{10,9,2,5,3,7,101,18};
        System.out.println("lengthOfLIS(arr) = " + lengthOfLIS(arr));
    }

    static int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length];

        Arrays.fill(dp, 1);
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
        }


        int res = 0;
        for (int i : dp) {
            System.out.println(i);
            res = Math.max(res, i);
        }

        return res;
    }
}
